#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QRect>
#include <QDebug>
#include <QLabel>
#include <QButtonGroup>
#include <QCheckBox>
#include <QTimer>
#include <QDate>
#include <QString>
#include <QRegularExpression>
#include <QValidator>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <QShortcut>
#include <QTreeWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QLineEdit>
#include <QSpacerItem>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ////////////////enabled//////////////////
    /*
    //enabled: 描述一个控件是否处于可用状态（一个widget被禁用其子元素也会被禁用）
    QPushButton* button_1 = new QPushButton(this);
    button_1->setText("该按钮已禁用");
    button_1->setEnabled(false);
    connect(button_1, &QPushButton::clicked, this, &Widget::close);

    QPushButton* button_2 = new QPushButton(this);
    button_2->move(100, 200);
    button_2->setText("点击以启用被禁用的按钮");

    connect(button_2, &QPushButton::clicked, this, [button_1](){
        button_1->setEnabled(true);
        button_1->setText("该按钮已启用");
    });
    */

    ////////////////geometry//////////////////

    /*
    geometry: 包含三个部分：x, y, width, height
    QLabel* label = new QLabel(this);
    label->setText("女神女神，做我女朋友好不好");
    label->move(125, 100);

    QPushButton* buttonAgree = new QPushButton(this);
    buttonAgree->setText("同意");
    buttonAgree->move(100, 200);
    connect(buttonAgree, &QPushButton::clicked, this, [label](){
        label->setText("女神女神，嘴一个，mua～");
    });

    QPushButton* buttonReject = new QPushButton(this);
    buttonReject->setText("拒绝");
    buttonReject->move(300, 200);
    connect(buttonReject, &QPushButton::pressed, this, [this, buttonReject](){
        int width = this->geometry().width();
        int height = this->geometry().height();
        int x = rand() % width;
        int y = rand() % height;
        buttonReject->move(x, y);
        buttonReject->setText("不要嘛");
    });
    */

    //////////////QRect////////////////

    /*geometry and framegeometry
    QPushButton* button = new QPushButton(this);
    button->setText("Debug");
    connect(button, &QPushButton::clicked, this, [this](){
        QRect rect1 = this->geometry();
        QRect rect2 = this->frameGeometry();
        qDebug() << rect1;
        qDebug() << rect2;
    });
    */

    //////////////Icon 与 qrc机制////////////////

    /* 设置图标
    QIcon qicon("relative path to picture");
    this->setWindowIcon(qicon);
    qrc机制：
    解决了图片所在路径在用户机上不存在和用户误删图片的问题。
    给qt项目引入一个额外的xml路径，后缀名为.qrc，在这个xml中，将资源导入进来
    并进行记录。
    qt在编译项目时，会找到图片内容，提取出其中的二进制数据，将其转化为
    二进制代码，将这些数据转化成C++代码，最终编译到exe文件里。
    这些二进制代码实际上就是一个大的char数组
    但是这种机制对大文件就没用了。
    可以新建一个qrc文件，创建一个prefix，在同级目录中add files
    qrc访问方式：QIcon qicon(":/filename")
    */

    //////////////Window opacity/////////////////

    /*windowOpacity
    qDebug() << this->windowOpacity();
    QPushButton* button = new QPushButton(this);
    button->setText("-");
    connect(button, &QPushButton::clicked, this, [this](){
        float opacity = this->windowOpacity();
        opacity -= 0.1;
        this->setWindowOpacity(opacity);
    });
    QPushButton* button2 = new QPushButton(this);
    button2->move(100, 0);
    button2->setText("+");
    connect(button2, &QPushButton::clicked, this, [this](){
        float opacity = this->windowOpacity();
        opacity += 0.1;
        this->setWindowOpacity(opacity);
    });
    */

    //////////////pixmap来设置按钮图标或光标//////////////////

    //根据自己的文件来设置光标
    QPushButton* button = new QPushButton(this);
    button->setText("cursor");

    QPixmap pixmap(":/cursor.jpg");
    pixmap = pixmap.scaled(100, 100); //对图片进行缩放
    QCursor cursor(pixmap, 10, 10); //10, 10是热点，即实际点击的位置
    button->setCursor(cursor);


    ///////////////构件font对象来设置label字体属性/////////////////
    /*构建font属性
    QLabel* label = new QLabel(this);
    label->setText("这是一段文本以供修改");

    先去构建一个字体对象
    QFont font;
    font.setFamily("仿宋");
    font.setPixelSize(30);
    font.setItalic(true);
    font.setBold(true);
    font.setUnderline(true);
    font.setStrikeOut(true); //设置删除线
    label->setFont(font);
    */

    ////////////////toolTips/////////////////

    /*设置构件提示信息——toolTips
    QPushButton* pushButton_yes = new QPushButton(this);
    pushButton_yes->setToolTip("这是一个yes按钮");
    pushButton_yes->setToolTipDuration(7000);
    pushButton_yes->move(200, 200);

    QPushButton* pushButton_no = new QPushButton(this);
    pushButton_no->setToolTip("这是一个no按钮");
    pushButton_no->setToolTipDuration(7000);
    */

    ///////////////FocusPolicy//////////////////

    /*FocusPolicy：NoFocus, TabFocus, ClickFocus, StrongFocus
    QPushButton* pushButton_focus = new QPushButton(this);
    pushButton_focus->setFocusPolicy(Qt::StrongFocus);
    */

    ///////////////stylesheet//////////////////

    //styleSheet，通过css设置widget样式。css，层叠样式表，进行网页开发的时候设置网页样式的方式
    //qss的设置，也是通过键值对的方式进行：
    //键和值之间用‘：’隔开，键值对之间用‘；’隔开

    ////////////////QPushButton/////////////////

    //QPushButton，继承自QAbstractButton（抽象类），是其他按钮的父类
    //(QPushButton, QCheckButton, QRadioButton, QToolButton)
    //text, icon, iconSize, shortCut(快捷键),
    //autoRepeat(设置鼠标按住不放时，是否重复点击)
    //autoRepeatDelay, autoRepeatInterval

    /*给按钮加一个图标
    QPushButton* button = new QPushButton(this);
    QIcon icon(":/yaling.svg");
    button->setIcon(icon);
    connect(button, &QPushButton::clicked, this, &Widget::close);
    button->setIconSize(QSize(50, 50)); //采取匿名对象的方式设置图标大小

    QPushButton* target = new QPushButton(this);
    target->setIcon(QIcon(":/yaling.svg"));
    target->move(300, 300);

    QPushButton* button_left = new QPushButton(this);
    button_left->setIcon(QIcon(":/qunfengfangxiangjianzuo.svg"));
    button_left->move(250, 400);

    QPushButton* button_right = new QPushButton(this);
    button_right->setIcon(QIcon(":/qunfengfangxiangjianyou.svg"));
    button_right->move(350, 400);

    connect(button_left, &QPushButton::clicked, this, [target](){
        target->setGeometry(target->geometry().x() - 5, target->geometry().y(), target->geometry().width(), target->geometry().height());
    });

    connect(button_right, &QPushButton::clicked, this, [target](){
        target->setGeometry(target->geometry().x() + 5, target->geometry().y(), target->geometry().width(), target->geometry().height());
    });
    */

    /////////////////shortcut and QKeySequence///////////////////

    /*
    //设置快捷键
    button_left->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W));
    button_right->setShortcut(QKeySequence("d"));

    //连发功能：键盘默认是可以连发的，鼠标不可以
    button_right->setAutoRepeat(true);
    */

    //////////////QRadioButton///////////////

    //QRadioButton
    //checkable, checked, autoExclusive 默认只能选中一个
    //ui->radioButton_not_known->setCheckable(false);
    //ui->radioButton_not_known->setDisabled(true);

    //////////////QButtonGroup///////////////

    /* radiobutton分组的使用
    QButtonGroup* group1 = new QButtonGroup(this);
    group1->addButton(ui->radioButton_burgur1);
    group1->addButton(ui->radioButton_burgur2);
    group1->addButton(ui->radioButton_burgur3);

    QButtonGroup* group2 = new QButtonGroup(this);
    group2->addButton(ui->radioButton_appetizer1);
    group2->addButton(ui->radioButton_appetizer2);
    group2->addButton(ui->radioButton_appetizer3);

    QButtonGroup* group3 = new QButtonGroup(this);
    group3->addButton(ui->radioButton_drink1);
    group3->addButton(ui->radioButton_drink2);
    group3->addButton(ui->radioButton_drink3);
    */

    /////////////////CheckBox//////////////////

    /*CheckBox，让可以在多个选项中，选择多个选项
    QLabel* label = new QLabel(this);
    label->setText("今天你的安排是：");
    QCheckBox* checkbox1 = new QCheckBox(this);
    QCheckBox* checkbox2 = new QCheckBox(this);
    QCheckBox* checkbox3 = new QCheckBox(this);

    checkbox1->move(100, 100);
    checkbox2->move(100, 200);
    checkbox3->move(100, 300);

    checkbox1->setText("学习");
    checkbox2->setText("玩游戏");
    checkbox3->setText("打工");

    QPushButton* button = new QPushButton(this);
    button->setText("确定");
    button->move(100, 400);
    connect(button, &QPushButton::clicked, this, &QPushButton::close);
    */

    /////////////TextFormat//////////////

    //纯文本，最普通的文本；富文本，内容更丰富的文本，支持html；markdown，
    //最常用的文档格式，其中内置了各种特殊符号来表示文档格式；autotext，根据
    //文本内容自动决定文本格式。
    //pixmap，label中含有的图片；QTextEdit，多行编辑框，带有滚动条
    //openExternalLinks, buddy（伙伴），wordWarp（自动换行）

    /*TextFormat
    把第一个label设置成显示纯文本。
    QLabel* label_1 = new QLabel(this);
    QLabel* label_2 = new QLabel(this);
    QLabel* label_3 = new QLabel(this);
    QLabel* label_4 = new QLabel(this);

    label_1->move(100, 100);
    label_2->move(100, 200);
    label_3->move(100, 300);
    label_4->move(100, 400);

    label_1->setTextFormat(Qt::PlainText);
    label_2->setTextFormat(Qt::RichText);
    label_3->setTextFormat(Qt::MarkdownText);
    label_4->setTextFormat(Qt::AutoText);

    label_1->setText("<b>这是一段纯文本</b>");
    label_2->setText("<b>这是一段富文本</b>"); //'<b>'表示加粗文本
    label_3->setText("# 这是一段markdown文本"); //'# '表示加粗加大
    label_4->setText("这是一段autotext文本");
    */

    /*给label设置图片
    QLabel* label = new QLabel(this);
    label->setGeometry(0, 0, this->geometry().width(), this->geometry().height());
    QPixmap pixmap(":/yaling.svg");
    label->setPixmap(pixmap); //但是这里大概率填不满，因为图片的尺寸不匹配
    label->setScaledContents(true); //将label中的图片设置的和窗口一样大
    */ //但是这样设置只能一次性填满不能继续自动填充

    /* 事件的概念：
    Qt中表示用户操作的只有两个东西：信号和事件
    在我们拖动窗口的过程中，resizeEvent事件就会被持续触发，可以重写父类
    的resizeEvent虚函数，构成多态
    */

    //////////////setAlignment来设置label文本格式////////////////

    /*
    ui->label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);

    ui->label_2->setText("这是一段很长的文本..................................这是一段很长的文本..................................这是一段很长的文本..................................这是一段很长的文本..................................");
    ui->label_2->setWordWrap(true); //设置自动换行

    ui->label_3->setText("这是一段文本");
    ui->label_3->setIndent(50); //设置自动缩进，缩进大小为50像素
    //这里的缩进不是首行缩进，而是每一行都缩进
    ui->label_2->setMargin(10); //设置文本边距：四周都有
    */

    /*
    ui->label->setBuddy(ui->radioButton);
    ui->label_2->setBuddy(ui->radioButton_2);
    Qt中可以使用&A，来给label绑定快捷键，如果再设置了伙伴关系，
    那么还想当于给伙伴按钮绑定了快捷键
    */

    ////////////QTimer//////////////

    //设置value或者intValue的接口是display
    //mode，设置进制，只有十进制支持小数

    //先设置一个计时器：
    //采用QTimer的做法
    /*
    ui->lcdNumber->display(4); //这里其实就是等价于setIntValue，但是函数不叫那个名字
    QTimer* timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, [timer, this](){
        int value = ui->lcdNumber->intValue();

        if(value <= 0)
        {
            timer->stop();
            this->close();
        }


        //采取C++11的sleep_for
        std::this_thread::sleep_for(std::chrono::milliseconds(1000));
        ui->lcdNumber->display(value - 1);
    });
    timer->start(1000);
    */

    /*采取C++11线程的做法：在Qt中，不能使用非主线程修改界面，只有主线程拥有修改界面的权利，以防止线程安全的问题影响桌面
    std::thread t1([this](){
        int value = ui->lcdNumber->intValue();
        if(value <= 0)
        {
            return;
        }
        ui->lcdNumber->display(value - 1);
    });
    t1.join();
    */

    //////////////progress bar//////////////

    /*进度条
    QTimer* timer = new QTimer(this);
    ui->progressBar->setValue(0);
    ui->progressBar->setStyleSheet("QProgressBar::chunk{background-color: green;}");
    connect(timer, &QTimer::timeout, this, &Widget::handle);
    timer->start(100);
    */

    ////////////QCalenderWidget///////////////

    /*QCalenderWidget
    connect(ui->calendarWidget, &QCalendarWidget::selectionChanged, this, &Widget::handle);
    */

    //////////////QLineEdit//////////////

    /*QLineEdit，其中text的值既可以通过代码，也可以通过直接进行修改
    inputMask（输入格式限制）, maxLength（最大长度）, frame（边框）, echoMode(*代替密码字符), placeHolder(灰色的在用户输入前出现的“请输入姓名”)，clearButtonEnabled（当存在输入内容时，一键清除所有内容）
    ui->lineEdit_name->setPlaceholderText("请输入姓名");
    ui->lineEdit_name->setClearButtonEnabled(true);

    ui->lineEdit_password->setPlaceholderText("请输入密码");
    ui->lineEdit_password->setClearButtonEnabled(true);
    ui->lineEdit_password->setEchoMode(QLineEdit::Password); //设置回显模式

    ui->lineEdit_phone->setPlaceholderText("请输入电话");
    ui->lineEdit_phone->setClearButtonEnabled(true);
    ui->lineEdit_phone->setInputMask("000-0000-0000");
    */

    //////////////QRegularExpression and validator//////////////

    /*正则表达式QRegularExpreesion，给输入框设置验证器
    QRegularExpression regExp("^1\\d{10}$"); //以1开头，往后是数字（转义字符），十个数字
    //给单行输入框设置验证器
    ui->lineEdit->setValidator(new QRegularExpressionValidator(regExp));
    */

    /*
    ui->lineEdit->setEchoMode(QLineEdit::Password);
    ui->lineEdit_2->setEchoMode(QLineEdit::Password);
    */

    /*
    ui->lineEdit->setEchoMode(QLineEdit::Password);
*/

    ///////////////QcomboBox and QSpinBox and QTimeEdit and QSliders///////////////

    //TextEdit

    /*QCombo Box表示下拉框
    std::ifstream menu("/Users/wangjiale/Desktop/code/qt/nomallyUsedWidget/menu.txt");
    if(!menu.is_open())
    {
        qDebug() << "ifstream fail";
        return;
    }
    std::string line;
    while(std::getline(menu, line))
    {
        ui->comboBox->addItem(QString::fromStdString(line)); //将std::string转化为QString
    }
    menu.close();

    //QSpinBox 微调框（整数）QDoubleSpinBox（小数）
    ui->spinBox->setValue(1);
    ui->spinBox->setRange(0, 5);
    */

    //QDateTimeEdit
    //y表示年份，M表示月份，d表示日期，H表示小时，m表示分钟，s表示秒
    //Qt::LocalTime; Qt::UTC，英国格林威治天文台标准时间
    //ui->label->setText("请输入起止时间");

    /*
    ui->horizontalSlider->setMinimum(100);
    ui->horizontalSlider->setMaximum(2000);
    ui->horizontalSlider->setValue(800);
    ui->horizontalSlider->setSingleStep(50);

    ui->verticalSlider->setMinimum(100);
    ui->verticalSlider->setMaximum(1500);
    ui->verticalSlider->setValue(600);
    ui->verticalSlider->setSingleStep(50);

    QShortcut* shortcut1 = new QShortcut(this);
    QShortcut* shortcut2 = new QShortcut(this);
    shortcut1->setKey(QKeySequence("-"));
    shortcut2->setKey(QKeySequence("="));

    connect(shortcut1, &QShortcut::activated, this, &Widget::subValue);
    connect(shortcut2, &QShortcut::activated, this, &Widget::addValue);

    QShortcut* shortcut3 = new QShortcut(this);
    shortcut3->setKey(QKeySequence(Qt::Key_A + Qt::Key_Plus));
    QShortcut* shortcut4 = new QShortcut(this);
    shortcut4->setKey(QKeySequence(Qt::Key_A + Qt::Key_Shift))
    */

    ////////////////QListWdiget and QTableWidget/////////////////

    /*多元素控件
    //MVC， model，view，controller，数据、视图、控制器
    //xxview，只实现了view，xxwidget基于xxview实现了三者，开箱即用
    //QListWidget，列表中的每一个元素、每一项称为是一个item
    ui->listWidget->addItem("C++");
    ui->listWidget->addItem("Java");
    ui->listWidget->addItem(new QListWidgetItem("Python"));
    */

    /////////////////tableWidget///////////////////
    /*ui->lineEdit->setPlaceholderText("请输入要添加的列名");

    //新建三行
    ui->tableWidget->insertRow(0);
    ui->tableWidget->insertRow(1);
    ui->tableWidget->insertRow(2);

    //新建三列
    ui->tableWidget->insertColumn(0);
    ui->tableWidget->insertColumn(1);
    ui->tableWidget->insertColumn(2);

    //给表头新建三个元素
    ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("姓名"));
    ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("年龄"));
    ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("学号"));

    ui->tableWidget->setItem(0, 0, new QTableWidgetItem("张三"));
    ui->tableWidget->setItem(0, 1, new QTableWidgetItem("20"));
    ui->tableWidget->setItem(0, 2, new QTableWidgetItem("1001"));

    ui->tableWidget->setItem(1, 0, new QTableWidgetItem("李四"));
    ui->tableWidget->setItem(1, 1, new QTableWidgetItem("19"));
    ui->tableWidget->setItem(1, 2, new QTableWidgetItem("1002"));

    ui->tableWidget->setItem(2, 0, new QTableWidgetItem("王五"));
    ui->tableWidget->setItem(2, 1, new QTableWidgetItem("20"));
    ui->tableWidget->setItem(2, 2, new QTableWidgetItem("1003"));

    connect(ui->pushButton_row, &QPushButton::clicked, this, [this](){
        int row_tol = ui->tableWidget->rowCount();
        ui->tableWidget->insertRow(row_tol);
    });

    connect(ui->pushButton_col, &QPushButton::clicked, this, [this](){
        int col_tol = ui->tableWidget->columnCount();
        ui->tableWidget->insertColumn(col_tol);
        ui->tableWidget->setHorizontalHeaderItem(col_tol, new QTableWidgetItem(ui->lineEdit->text()));
    });

    connect(ui->pushButton_delete_row, &QPushButton::clicked, this, [this](){
        int cur_row = ui->tableWidget->currentRow();
        ui->tableWidget->removeRow(cur_row);
    });

    connect(ui->pushButton_delete_col, &QPushButton::clicked, this, [this](){
        int cur_col = ui->tableWidget->currentColumn();
        ui->tableWidget->removeColumn(cur_col);
    });
    */

    /////////////treeWidget//////////////

    /*
    ui->treeWidget->setHeaderLabel("动物");

    QTreeWidgetItem* item1 = new QTreeWidgetItem();
    item1->setText(0, "猫");
    ui->treeWidget->addTopLevelItem(item1);

    QTreeWidgetItem* item2 = new QTreeWidgetItem();
    item2->setText(0, "狗");
    ui->treeWidget->addTopLevelItem(item2);

    QTreeWidgetItem* item3 = new QTreeWidgetItem();
    item3->setText(0, "鸟");
    ui->treeWidget->addTopLevelItem(item3);

    QTreeWidgetItem* item4 = new QTreeWidgetItem();
    item4->setText(0, "布偶猫");
    item1->addChild(item4);

    QTreeWidgetItem* item5 = new QTreeWidgetItem();
    item5->setText(0, "史宾格");
    item2->addChild(item5);

    QTreeWidgetItem* item6 = new QTreeWidgetItem();
    item6->setText(0, "喜鹊");
    item3->addChild(item6);
    */

    ///////////////QGroupBox/////////////////

    ////将多个组件设置在一起，

    ///////////////QTabWidget/////////////////
    /// 起到带有标签页的效果

    /*在每个标签页中添加一个label
    QLabel* label_1 = new QLabel(ui->tab);
    label_1->setText("标签页一");
    label_1->resize(100, 50);

    QLabel* label_2 = new QLabel(ui->tab_2);
    label_2->setText("标签页二");
    label_2->resize(100, 50);

    connect(ui->pushButton, &QPushButton::clicked, this, [this](){
        QWidget* w = new QWidget();
        int count = ui->tabWidget->count();
        ui->tabWidget->addTab(w, QString("Tab ") + QString::number(count + 1));

        QLabel* label = new QLabel(w);
        label->setText(QString("Tab") + QString::number(count + 1));
        label->resize(100, 50);

        ui->tabWidget->setCurrentIndex(count);
    });

    connect(ui->pushButton_2, &QPushButton::clicked, this, [this](){
        int index = ui->tabWidget->currentIndex();
        ui->tabWidget->removeTab(index);
    });
    */

    /////////////////QVBoxLayout///////////////////

    /*
    //需要创建布局管理器对象
    QPushButton* pushButton = new QPushButton("按钮一");
    QPushButton* pushButton_2 = new QPushButton("按钮二");
    QPushButton* pushButton_3 = new QPushButton("按钮三");

    QVBoxLayout* layout = new QVBoxLayout();
    layout->addWidget(pushButton);
    layout->addWidget(pushButton_2);
    layout->addWidget(pushButton_3);

    this->setLayout(layout);
    //一个widget只能设置一个QVBoxLayout，在代码中创建只创建了一个layout；
    //而在Qtdesigner当中，还创建了一个qwidget，所以可以设置多个，而且设置了以后
    //不再提供item随标签页放大而放大缩小而缩小。
    */

    /////////////////QHBoxLayout/////////////////

    /*
    QVBoxLayout* layout = new QVBoxLayout();
    QPushButton* button1 = new QPushButton("Button1");
    QPushButton* button2 = new QPushButton("Button2");
    layout->addWidget(button1);
    layout->addWidget(button2);

    QHBoxLayout* layout2 = new QHBoxLayout();
    QPushButton* button3 = new QPushButton("Button3");
    QPushButton* button4 = new QPushButton("Button4");
    layout2->addWidget(button3);
    layout2->addWidget(button4);
    layout->addLayout(layout2);
    this->setLayout(layout);
    */

    ////////////////QGridLayout//////////////////

    /*
    QGridLayout* layout = new QGridLayout();
    QPushButton* button1 = new QPushButton("button1");
    QPushButton* button2 = new QPushButton("button1");
    QPushButton* button3 = new QPushButton("button1");
    QPushButton* button4 = new QPushButton("button1");

    layout->addWidget(button1, 0, 0);
    layout->addWidget(button2, 0, 1);
    layout->addWidget(button3, 1, 0);
    layout->addWidget(button4, 1, 1);

    button1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    button2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    button3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    button4->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    this->setLayout(layout);

    //设置widget比例
    layout->setColumnStretch(0, 1);
    layout->setColumnStretch(1, 2);
    */

    //////////////QFormLayout///////////////

    /*
    QFormLayout* layout = new QFormLayout();
    this->setLayout(layout);

    QLabel* label1 = new QLabel("name");
    QLabel* label2 = new QLabel("gender");
    QLabel* label3 = new QLabel("phone");

    QLineEdit* lineEdit1 = new QLineEdit();
    QLineEdit* lineEdit2 = new QLineEdit();
    QLineEdit* lineEdit3 = new QLineEdit();

    layout->addRow(label1, lineEdit1);
    layout->addRow(label2, lineEdit2);
    layout->addRow(label3, lineEdit3);

    QPushButton* button = new QPushButton("submit");
    layout->addRow(nullptr, button);
    */

    //////////////QSpacerItem///////////////

    /*
    QHBoxLayout* layout = new QHBoxLayout();
    this->setLayout(layout);

    QLabel* label1 = new QLabel("Label1");
    QLabel* label2 = new QLabel("Label2");
    QSpacerItem* spacer = new QSpacerItem(200, 20);

    layout->addWidget(label1);
    layout->addSpacerItem(spacer);
    layout->addWidget(label2);
    */
}

/*
void Widget::on_pushButton_insert_top_item_clicked()
{
    QTreeWidgetItem* new_item = new QTreeWidgetItem();
    new_item->setText(0, ui->lineEdit->text());
    ui->lineEdit->clear();
    ui->treeWidget->addTopLevelItem(new_item);
}

void Widget::on_pushButton_insert_given_item_clicked()
{
    QTreeWidgetItem* new_item = new QTreeWidgetItem();
    new_item->setText(0, ui->lineEdit->text());
    ui->lineEdit->clear();
    QTreeWidgetItem* cur_item = ui->treeWidget->currentItem();
    if(cur_item == nullptr)
    {
        return;
    }
    cur_item->addChild(new_item);
}

void Widget::on_pushButton_delete_item_clicked()
{
    QTreeWidgetItem* current_item = ui->treeWidget->currentItem();
    if(current_item == nullptr)
    {
        return;
    }
    QTreeWidgetItem* parent = current_item->parent();
    if(parent == nullptr)
    {
        int index = ui->treeWidget->indexOfTopLevelItem(current_item);
        ui->treeWidget->takeTopLevelItem(index);
    }
    else
    {
        parent->removeChild(current_item);
    }
}
*/

/*
void Widget::on_pushButton_insert_clicked()
{
    ui->listWidget->addItem(ui->lineEdit->text());
    ui->lineEdit->clear();
}

void Widget::on_pushButton_delete_clicked()
{
    int row = ui->listWidget->currentRow();
    if(row < 0)
    {
        return;
    }
    ui->listWidget->takeItem(row);
}

void Widget::on_listWidget_currentItemChanged(QListWidgetItem* current, QListWidgetItem* privious)
{
    if(current != nullptr)
    {
        qDebug() << "当前选中的item：" << current->text();
    }
    if(privious != nullptr)
    {
        qDebug() << "上一次选中的item" << privious->text();
    }
}
*/

/*
void Widget::subValue()
{
    int value = ui->horizontalSlider->value();
    if(value < ui->horizontalSlider->minimum())
    {
        return;
    }
    ui->horizontalSlider->setValue(value - 50);
}

void Widget::addValue()
{
    int value = ui->horizontalSlider->value();
    if(value > ui->horizontalSlider->maximum())
    {
        return;
    }
    ui->horizontalSlider->setValue(value + 50);
}

void Widget::on_horizontalSlider_valueChanged(int value)
{
    QRect rect;
    rect = this->geometry();
    this->setGeometry(rect.x(), rect.y(), value, rect.height());
}

void Widget::on_verticalSlider_valueChanged(int value)
{
    QRect rect;
    rect = this->geometry();
    this->setGeometry(rect.x(), rect.y(), rect.width(), value);
}
*/

/*
void Widget::on_dial_valueChanged(int value)
{
    //QDial旋钮——通过旋钮控制窗口的透明度
    this->setWindowOpacity(value / 100.0);
}
*/

/*
void Widget::on_pushButton_clicked()
{
    QDateTime startDate = ui->dateTimeEdit->dateTime();
    QDateTime endDate = ui->dateTimeEdit_2->dateTime();

    //计算天数的差值
    int days = startDate.daysTo(endDate);
    std::stringstream info;
    std::string result;
    info << "已经过去了" << days << "天";
    info >> result;
    ui->label->setText(result.c_str());
    info.clear();
    result.clear();

    //计算秒数的差值
    int seconds = startDate.secsTo(endDate);
    info << "已经过去了" << seconds << "秒";
    info >> result;
    ui->label_4->setText(result.c_str());
    info.clear();
    result.clear();

    //计算分钟的差值

    int minutes = seconds / 60;
    info << "已经过去了" << minutes << "分钟";
    info >> result;
    ui->label_3->setText(result.c_str());
    info.clear();
    result.clear();

    //计算小时的差值
    int hours = minutes/60;
    info << "已经过去了" << hours << "小时";
    info >> result;
    ui->label_2->setText(result.c_str());
}
*/

/*
void Widget::on_pushButton_clicked()
{
    qDebug() << ui->comboBox->currentText() << ui->spinBox->value();
}
*/

/*
void Widget::on_pushButton_clicked()
{
    QString string;
    string = ui->comboBox->currentText() + "+" + ui->comboBox_2->currentText() + "+" + ui->comboBox_3->currentText();
    ui->label_4->setText(string);
}
*/

/*
void Widget::on_textEdit_textChanged()
{
    ui->label->setText(ui->textEdit->toPlainText());
}

void Widget::on_textEdit_selectionChanged()
{
    //根据选择的文本光标来确定选中的是哪些文本
    QTextCursor cursor = ui->textEdit->textCursor();
    ui->label->setText(cursor.selectedText());
}

void Widget::on_textEdit_positionChanged()
{
    QTextCursor cursor = ui->textEdit->textCursor();
    qDebug() << cursor.position();
}
*/

/*
void Widget::on_checkBox_toggled(bool check)
{
    if(check)
    {
        ui->lineEdit->setEchoMode(QLineEdit::Normal);
    }
    else
    {
        ui->lineEdit->setEchoMode(QLineEdit::Password);
    }
}
*/

/*
void Widget::on_lineEdit_2_textEdited()
{
    QString text1 = ui->lineEdit->text();
    QString text2 = ui->lineEdit_2->text();
    if(text1.isEmpty() || text2.isEmpty())
    {
        ui->label->setText("请输入密码");
    }
    else if(text1 == text2)
    {
        ui->label->setText("输入的密码一致");
    }
    else
    {
        ui->label->setText("输入的密码不一致");
    }
}
*/

/*
void Widget::on_lineEdit_textEdited(const QString& text)
{
    //获取正则表达式
    QString content = text;
    int pos = 0;
    //从pos开始，验证content内容
    if(ui->lineEdit->validator()->validate(content, pos) == QValidator::Acceptable)
    {
        ui->pushButton->setEnabled(true);
    }
    else
    {
        ui->pushButton->setEnabled(false);
    }
}
*/

/*
void Widget::handle()
{
    QDate date = ui->calendarWidget->selectedDate();
    ui->label->setText(date.toString());
}
*/

/*
void Widget::handle()
{
    int value = ui-> progressBar->value();
    if(value >= 101)
    {
        return;
    }
    ui->progressBar->setValue(value + 1);
}
*/

Widget::~Widget()
{
    delete ui;
}

/*
void Widget::resizeEvent(QResizeEvent* event)
{
    ui->label->setGeometry(0, 0, event->size().width(), event->size().height());
}
*/

/*
void Widget::on_radioButton_male_clicked()
{
    ui->label->setText("您选择的性别是男性");
}

void Widget::on_radioButton_female_clicked()
{
    ui->label->setText("您选择的性别是女性");
}

void Widget::on_radioButton_not_known_clicked()
{
    ui->label->setText("您选择的性别是未知（当前不可选）");
}
*/

/*
void Widget::on_radioButton_male_pressed()
{
    ui->label->setText("pressed");
}

void Widget::on_radioButton_female_released()
{
    ui->label->setText("released");
}

void Widget::on_radioButton_not_known_toggled()
{
    ui->label->setText("toggled");
}
*/

/*
void Widget::on_pushButton_day_clicked()
{
    //RGB：在计算机中，使用一个字节来表示R，一个字节表示G，一个字节表示B（红绿蓝）
    //具体可通过取色器来进行调整
    //窗口
    this->setStyleSheet("background-color: rgb(240, 240, 240)");
    //输入框
    ui->lineEdit->setStyleSheet("background-color: white; color: black");
    //按钮
    ui->pushButton_day->setStyleSheet("color: black");
    ui->pushButton_night->setStyleSheet("color: black");
}

void Widget::on_pushButton_night_clicked()
{
    //窗口
    this->setStyleSheet("background-color: black");
    //输入框
    ui->lineEdit->setStyleSheet("background-color: grey; color: white");
    //按钮
    ui->pushButton_day->setStyleSheet("background-color: grey; color: white");
    ui->pushButton_night->setStyleSheet("background-color: grey; color: white");
}
*/

/*
void Widget::on_pushButtonUp_clicked()
{
    QRect rect = ui->pushButtonTarget->geometry();
    // rect.setY(rect.y() - 5);
    // ui->pushButtonTarget->setGeometry(rect);
    ui->pushButtonTarget->setGeometry(rect.x(), rect.y() - 5, rect.width(), rect.height());
}

void Widget::on_pushButtonDown_clicked()
{
    QRect rect = ui->pushButtonTarget->geometry();
    // rect.setY(rect.y() + 5);
    // ui->pushButtonTarget->setGeometry(rect);
    ui->pushButtonTarget->setGeometry(rect.x(), rect.y() + 5, rect.width(), rect.height());
}

void Widget::on_pushButtonRight_clicked()
{
    QRect rect = ui->pushButtonTarget->geometry();
    // rect.setX(rect.x() + 5);
    // ui->pushButtonTarget->setGeometry(rect);
    ui->pushButtonTarget->setGeometry(rect.x() + 5, rect.y(), rect.width(), rect.height());
}

void Widget::on_pushButtonLeft_clicked()
{
    QRect rect = ui->pushButtonTarget->geometry();
    // rect.setX(rect.x() - 5);
    // ui->pushButtonTarget->setGeometry(rect);
    ui->pushButtonTarget->setGeometry(rect.x() - 5, rect.y(), rect.width(), rect.height());
}
*/

/*
void Widget::on_pushButton_agree_clicked()
{
    ui->label_question->setText("女神女神，嘴一个，mua！");
}


void Widget::on_pushButton_reject_clicked()
{

    int width = this->geometry().width();
    int height = this->geometry().height();

    int x = rand() % width;
    int y = rand() % height;

    ui->pushButton_reject->move(x, y);
}
*/
